package com.examination.mlib.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.examination.mlib.R;


public class TitleBar extends RelativeLayout {

    private RelativeLayout titleBarBg;
    private TextView titleBarTitle;
    private ImageView titleBarBack;

    public TitleBar(Context context) {
        super(context);
    }

    public TitleBar(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.title_bar_layout, this);
        titleBarBg = (RelativeLayout) findViewById(R.id.title_bar_bg);
        titleBarTitle = (TextView) findViewById(R.id.title_bar_title);
        titleBarBack = (ImageView) findViewById(R.id.title_bar_back);
    }

    public TitleBar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    /**
     * 设置Titlebar颜色
     *
     * @param color
     */
    public void setTitleBarBg(int color) {
        titleBarBg.setBackgroundColor(getResources().getColor(color));
    }

    /**
     * 设置Titlebar标题
     *
     * @param title
     */
    public void setTitleBarTitle(String title) {
        titleBarTitle.setText(title);
    }

    /**
     * 设置Titlebar标题颜色
     *
     * @param color
     */
    public void setTitleBarColor(int color) {
        titleBarTitle.setTextColor(getResources().getColor(color));
    }

    /**
     * 设置点击返回back
     *
     * @param click
     */
    public void setTitleBarBackClick(View.OnClickListener click) {
        titleBarBack.setOnClickListener(click);
    }

}
